package com.shark.springbootcms.controller;

import com.shark.springbootcms.common.Result;
import com.shark.springbootcms.form.MenuForm;
import com.shark.springbootcms.service.MenuService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @RequestMapping("/list")
    public Result list() {
        return menuService.list();
    }

    @PostMapping("/add")
    public Result addRole(@RequestBody MenuForm form) {
        return menuService.addMenu(form);
    }

    @PostMapping("/edit/{id}")
    public Result edit(@RequestBody MenuForm form, @PathVariable("id") String id) {
        form.setId(id);
        return menuService.edit(form);
    }

    @GetMapping("/getParentMenu")
    public Result getParentMenu() {
        return menuService.getParentMenu();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") String id) {
        return menuService.delete(id);
    }

}
